package cn.kgm.makeGodV2.emotion;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 核心数据类 - 代表NPC的五维性格
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PersonalityTrait {

    private Double openness;            // 开放性
    private Double conscientiousness;   // 尽责性
    private Double extraversion;        // 外向性
    private Double agreeableness;       // 宜人性
    private Double neuroticism;         // 神经质

    public PersonalityTrait(double o, double c, double e, double a, double n) {
        this.openness = clamp(o, 0.0, 100.0);
        this.conscientiousness = clamp(c, 0.0, 100.0);
        this.extraversion = clamp(e, 0.0, 100.0);
        this.agreeableness = clamp(a, 0.0, 100.0);
        this.neuroticism = clamp(n, 0.0, 100.0);
    }

    // 创建预定义人格类型
    public static PersonalityTrait createOptimistic() {
        return new PersonalityTrait(70.0, 60.0, 80.0, 75.0, 20.0);
    }

    public static PersonalityTrait createPessimistic() {
        return new PersonalityTrait(50.0, 70.0, 30.0, 40.0, 85.0);
    }

    public static PersonalityTrait createAdventurous() {
        return new PersonalityTrait(90.0, 50.0, 75.0, 50.0, 40.0);
    }

    public static PersonalityTrait createStable() {
        return new PersonalityTrait(60.0, 80.0, 50.0, 70.0, 25.0);
    }

    private double clamp(double value, double min, double max) {
        return Math.max(min, Math.min(max, value));
    }

    // 根据人格特质生成基础情感倾向 (0.0-100.0范围)
    public EmotionalVector getBaseEmotionalTendency() {
        // 高外倾性 -> 更高愉悦度和唤醒度
        // 高神经质 -> 更低愉悦度，更高唤醒度
        // 高宜人性 -> 更高愉悦度
        double baseValence = 50.0 + (extraversion - 50.0) * 0.3 + (agreeableness - 50.0) * 0.25 - (neuroticism - 50.0) * 0.35;
        double baseArousal = 50.0 + (neuroticism - 50.0) * 0.4 + (extraversion - 50.0) * 0.2;
        double baseDominance = 50.0 + (extraversion - 50.0) * 0.25 - (neuroticism - 50.0) * 0.25;

        return new EmotionalVector(baseValence, baseArousal, baseDominance);
    }

    // Getters
    public double getOpenness() {
        return openness;
    }

    public double getConscientiousness() {
        return conscientiousness;
    }

    public double getExtraversion() {
        return extraversion;
    }

    public double getAgreeableness() {
        return agreeableness;
    }

    public double getNeuroticism() {
        return neuroticism;
    }

    @Override
    public String toString() {
        return String.format("O:%.1f, C:%.1f, E:%.1f, A:%.1f, N:%.1f",
                openness, conscientiousness, extraversion, agreeableness, neuroticism);
    }
}
